package com.ddproject;

import java.sql.Connection;  
import java.sql.DriverManager;  
import java.sql.ResultSet;  
import java.sql.Statement;  
import java.util.ArrayList;
import java.util.List;
  
public class Test {  
  
    public static void main(String args[]) {  
        String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=ddproject;user=sa;password=sa";//sa身份连接  
        // Declare the JDBC objects.  
        Connection con = null;  
        Statement stmt = null;  
        ResultSet rs = null;  
        List<Object> list = new ArrayList<Object>();
        try {  
            // Establish the connection.  
            System.out.println("begin.");  
           // Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  
            con = DriverManager.getConnection(url);  
            System.out.println("end.");  
  
            // Create and execute an SQL statement that returns some data.  
            String SQL = "SELECT  * FROM cgml where  XZHQM LIKE '%张家口%'";  
            stmt = con.createStatement();  
            rs = stmt.executeQuery(SQL);  
  
            // Iterate through the data in the result set and display it.  
            while (rs.next()) {  
                System.out.println(rs.getString(4) + " " + rs.getString(17));  
            }  
        }  
  
        // Handle any errors that may have occurred.  
        catch (Exception e) {  
            e.printStackTrace();  
        }  
  
        finally {  
            if (rs != null)  
                try {  
                    rs.close();  
                } catch (Exception e) {  
                }  
            if (stmt != null)  
                try {  
                    stmt.close();  
                } catch (Exception e) {  
                }  
            if (con != null)  
                try {  
                    con.close();  
                } catch (Exception e) {  
                }  
        }  
    }  
}  
